package com.fzu.mmdbproxyframework.cluster.passcloud;

import java.util.HashMap;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class Monitor {
	public static JSONObject listBasicMetrics(HashMap<String, String> params) {
		String result = SendRequest.sendRequest(
				InternetwareCmd.ListBasicMetricsCmd, params);
		if (null == result)
			return null;
		JSONObject obj = JSONObject.fromObject(result).getJSONObject(
				InternetwareCmd.ListBasicMetricsRes);
		if (obj.isEmpty())
			return null;
		int count = obj.getInt("count");
		JSONArray o = obj.getJSONArray("basicmetrics");
		return (JSONObject) o.get(count - 1);
	}
	public static JSONObject listIfMetrics(HashMap<String, String> params) {
		String result = SendRequest.sendRequest(
				InternetwareCmd.ListIfMetricsCmd, params);
		if (null == result)
			return null;
		JSONObject obj = JSONObject.fromObject(result).getJSONObject(
				InternetwareCmd.ListIfMetricsRes);
		if (obj.isEmpty())
			return null;
		int count = obj.getInt("count");
		JSONArray o = obj.getJSONArray("ifmetrics");
		return (JSONObject) o.get(count - 1);
	}
	public static JSONObject listCpuMetrics(HashMap<String, String> params) {
		String result = SendRequest.sendRequest(
				InternetwareCmd.listCpuMetricsCmd, params);
		if (null == result)
			return null;
		JSONObject obj = JSONObject.fromObject(result).getJSONObject(
				InternetwareCmd.listCpuMetricsRes);
		if (obj.isEmpty())
			return null;
		int count = obj.getInt("count");
		JSONArray o = obj.getJSONArray("cpumetrics");
		return (JSONObject) o.get(count - 1);
	}
	public static JSONObject listDiskMetrics(HashMap<String, String> params) {
		String result = SendRequest.sendRequest(
				InternetwareCmd.listDiskMetricsCmd, params);
		if (null == result)
			return null;
		JSONObject obj = JSONObject.fromObject(result).getJSONObject(
				InternetwareCmd.listDiskMetricsRes);
		if (obj.isEmpty())
			return null;
		int count = obj.getInt("count");
		JSONArray o = obj.getJSONArray("diskmetrics");
		return (JSONObject) o.get(count - 1);
	}
	public static void main(String[] args) {
		HashMap<String, String> params = new HashMap<String, String>();
		params.put("hostid", "32e06727-53fb-451d-8f35-3074a46604ac");
		params.put("type", "HOST");
		System.out.println(listCpuMetrics(params));
	}
}
